/**
 * 游戏主界面
 */
declare var GLOBAL_MUSIC;
declare var GLOBAL_CHANNEL;
class GameScene extends eui.Component {
    private CURRENT_LEVEL: number;
    private numToChinese: Array<any> = ['一','二','三','四','五','六','七','八','九','十','十一','十二',
                '十三','十四','十五','十六','十七','十八','十九','二十','二十一','二十二','二十三','二十四','二十五']
    //初始化分数
    private SCORE_REGISTER = {
        math: 0,    //数感
        illation: 0,    //推理
        observation: 0, //观察
        space: 0,   //空间感
        memory: 0   //记忆力
    }

    private BASE_COMP: any;
    private levelLabel;
    private GAME_PANEL: any;
    private LEVEL_CONFIG: any;
    private CURRENT_CONFIG: any;
    private CURRENT_TARGET_NUM: number = 0;
    private TARGET_NUM: number;
    private SCORE_BOARD: any;
    private SCORE_WRAPPER: any;
    private LEVEL_BOARD: any;
    private myMask;
    private levelTitle;
    private TOUCH_AREA;
    private SUCCESS_PAGE;
    private FAIL_PAGE;
    private COUNTDOWN;
    private COUNTDOWN_THREAD;
    private TITLE;
    private LAST_COUNTER = [];
    private MUSIC_BOARD;
    private SOUND_THREAD;
    
    private MUSIC1;
    private MUSIC2;
    private MUSIC3;
    private MUSIC4;
    private MUSIC5;
    private MUSIC6;
    private MUSIC7;
    private MUSIC8;
    private MUSIC9;
    private MUSIC10;
    private MUSIC11;
    private MUSIC12;
    private MUSIC13;
    private MUSIC14;
    private MUSIC15;
    private MUSIC16;
    private MUSIC17;
    private MUSIC18;
    private MUSIC19;
    private MUSIC20;

    private MUSIC211;
    private MUSIC212;
    private MUSIC221;
    private MUSIC222;
    private MUSIC231;
    private MUSIC232;
    private MUSIC241;
    private MUSIC242;
    private MUSIC251;
    private MUSIC252;
    private QS_ID;
    private SUCCESS_MUSIC;
    private FAIL_MUSIC;
    private MUSIC_BTN;
    private BOOM_SOUND;
    private TIMELINE;
    private FRAME = 0;
    private frameCount = 0;
    private RIGHTSHADOW;

    private canClick;

    //记录一些所需要的信息
    private myOption: any = {};

    public constructor(stageHeight,stageWidth) {
        super();
        this.myOption.stageHeight = stageHeight;
        this.myOption.stageWidth = stageWidth;
        this.initMusic();
    }

    public init(){
        $.ajax({
            url: GLOBAL_PATH + '/question/report/take',
            method:'POST',
            headers: {
                'Content-Type': "application/json;charset=UTF-8"
            },
            data: JSON.stringify({userId: USER_ID}),
            success:(res) => {
                // if(JSON.parse(res).success){
                //    let data = JSON.parse(res);
                    // this.QS_ID = data.data.reportId;
                    this.initGameBase();
                // }
            }
        })
    }

    private initGameBase() {
        this.initMask();
        this.LEVEL_CONFIG = LevelConfig.getInstance();
        this.CURRENT_LEVEL = 23;
        let background = this.createBitmapByName('background_png');
        background.width = this.myOption.stageWidth;
        background.height = this.myOption.stageHeight;
        this.addChild(background);

        let bgother = this.createBitmapByName('bgother_png');
        bgother.width = this.myOption.stageWidth;
        bgother.height = 1138;
        bgother.y = this.myOption.stageHeight - 1138;
        this.addChild(bgother);

        this.BASE_COMP = new eui.Component();
        this.BASE_COMP.skinName = 'base';
        this.addChild(this.BASE_COMP);

        this.MUSIC_BOARD = new eui.Component();
        this.MUSIC_BOARD.skinName = 'musicBtn';
        this.MUSIC_BOARD.x = 0;
        this.MUSIC_BOARD.y = this.myOption.stageHeight/2 - this.MUSIC_BOARD.height/2;
        this.levelLabel = this.MUSIC_BOARD.getChildByName('levelLabel');

        this.TOUCH_AREA = new eui.Group();
        this.TOUCH_AREA.x = 0;
        this.TOUCH_AREA.y = 0;
        this.TOUCH_AREA.height = this.myOption.stageHeight;
        this.TOUCH_AREA.width = this.myOption.stageWidth;
        
        this.TITLE = this.BASE_COMP.getChildByName('title');
        this.COUNTDOWN = this.BASE_COMP.getChildByName('countDown');
        this.LEVEL_BOARD = this.BASE_COMP.getChildByName('level');
        this.SCORE_WRAPPER = this.BASE_COMP.getChildByName('scoreWrapper');
        this.SCORE_BOARD = this.BASE_COMP.getChildByName('score');
        this.MUSIC_BTN = this.BASE_COMP.getChildByName('musicBtn');
        this.TIMELINE = this.BASE_COMP.getChildByName('timeline');
        this.RIGHTSHADOW = this.BASE_COMP.getChildByName('rightShadow');

        this.MUSIC_BTN.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            if(this.CURRENT_LEVEL < 21) {
                this['MUSIC' + this.CURRENT_LEVEL].play(0,1);
                this.playMucis(this.CURRENT_CONFIG.duration)
            }else{
                this['MUSIC' + this.CURRENT_LEVEL + '2'].play(0,1);
                this.playMucis(this.CURRENT_CONFIG.duration)
            }
        })

        this.GAME_PANEL = new eui.Group();
        this.showLevelLabel();

    }

    private initMusic() {
        this.BOOM_SOUND = new egret.Sound();
        this.BOOM_SOUND.load('resource/music/boom.mp3');

        this.SUCCESS_MUSIC= new egret.Sound();
        this.SUCCESS_MUSIC.load('resource/music/success.mp3');
        
        this.FAIL_MUSIC= new egret.Sound();
        this.FAIL_MUSIC.load('resource/music/fail.mp3');

        this.MUSIC1= new egret.Sound();
        this.MUSIC1.load('resource/music/1.mp3');

        this.MUSIC2= new egret.Sound();
        this.MUSIC2.load('resource/music/2.mp3');

        this.MUSIC3= new egret.Sound();
        this.MUSIC3.load('resource/music/3.mp3');

        this.MUSIC4= new egret.Sound();
        this.MUSIC4.load('resource/music/4.mp3');

        this.MUSIC5= new egret.Sound();
        this.MUSIC5.load('resource/music/5.mp3');

        this.MUSIC6= new egret.Sound();
        this.MUSIC6.load('resource/music/67.mp3');

        this.MUSIC7= new egret.Sound();
        this.MUSIC7.load('resource/music/67.mp3');

        this.MUSIC8= new egret.Sound();
        this.MUSIC8.load('resource/music/89.mp3');

        this.MUSIC9= new egret.Sound();
        this.MUSIC9.load('resource/music/89.mp3');

        this.MUSIC10= new egret.Sound();
        this.MUSIC10.load('resource/music/67.mp3');

        this.MUSIC11= new egret.Sound();
        this.MUSIC11.load('resource/music/11.mp3');

        this.MUSIC12= new egret.Sound();
        this.MUSIC12.load('resource/music/1213.mp3');

        this.MUSIC13= new egret.Sound();
        this.MUSIC13.load('resource/music/1213.mp3');

        this.MUSIC14= new egret.Sound();
        this.MUSIC14.load('resource/music/14.mp3');

        this.MUSIC15= new egret.Sound();
        this.MUSIC15.load('resource/music/15.mp3');

        this.MUSIC16= new egret.Sound();
        this.MUSIC16.load('resource/music/1617.mp3');

        this.MUSIC17= new egret.Sound();
        this.MUSIC17.load('resource/music/1617.mp3');

        this.MUSIC18= new egret.Sound();
        this.MUSIC18.load('resource/music/1819.mp3');

        this.MUSIC19= new egret.Sound();
        this.MUSIC19.load('resource/music/1819.mp3');

        this.MUSIC20= new egret.Sound();
        this.MUSIC20.load('resource/music/20.mp3');
        

        this.MUSIC211= new egret.Sound();
        this.MUSIC211.load('resource/music/211.mp3');

        this.MUSIC212= new egret.Sound();
        this.MUSIC212.load('resource/music/212.mp3');
        
        this.MUSIC221= new egret.Sound();
        this.MUSIC221.load('resource/music/211.mp3');

        this.MUSIC222= new egret.Sound();
        this.MUSIC222.load('resource/music/212.mp3');

        this.MUSIC231= new egret.Sound();
        this.MUSIC231.load('resource/music/231.mp3');

        this.MUSIC232= new egret.Sound();
        this.MUSIC232.load('resource/music/232.mp3');
        
        this.MUSIC241= new egret.Sound();
        this.MUSIC241.load('resource/music/231.mp3');

        this.MUSIC242= new egret.Sound();
        this.MUSIC242.load('resource/music/232.mp3');

        this.MUSIC251= new egret.Sound();
        this.MUSIC251.load('resource/music/251.mp3');

        this.MUSIC252= new egret.Sound();
        this.MUSIC252.load('resource/music/252.mp3');
    }

    /**
     * 展示阴影遮罩层
    */
    private initMask() {
        this.myMask = new eui.Rect();
        this.myMask.width = this.myOption.stageWidth;
        this.myMask.height = this.myOption.stageHeight;
        this.myMask.fillColor = 0x000000;
        this.myMask.fillAlpha = 0.7
    }

    private createBitmapByName(name: string): eui.Image {
        let result = new eui.Image();
        let texture: egret.Texture = RES.getRes(name);
        result.texture = texture;
        return result;
    }

    private showLevelLabel() {
        this.CURRENT_CONFIG = this.LEVEL_CONFIG.getCurrentLevelConfig(this.CURRENT_LEVEL);
        this.LEVEL_BOARD.text = `${this.CURRENT_LEVEL}/25`
        this.addChild(this.myMask);
        this.addChild(this.MUSIC_BOARD);
        this.levelLabel.getChildByName('content').text = `第${this.numToChinese[this.CURRENT_LEVEL - 1]}关`;
        this.canClick = true;
        this.levelLabel.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            if(!this.canClick) return;
            this.canClick = false;
            this.COUNTDOWN.text = '15s';
            this.TIMELINE.width = 340;
            this.RIGHTSHADOW.x = 480;
            this.removeChild(this.myMask);
            this.removeChild(this.MUSIC_BOARD);
            if(this.CURRENT_LEVEL !== 25){
                setTimeout(() => {
                    if(this.CURRENT_CONFIG.preList){
                        this.FRAME = 0;
                        GLOBAL_MUSIC = this['MUSIC' + this.CURRENT_LEVEL + '1'];
                        GLOBAL_CHANNEL = this['MUSIC' + this.CURRENT_LEVEL + '1'].play(0,1);
                        this.playMucis(this.CURRENT_CONFIG.duration1) 
                    }else {
                        this.addEventListener( egret.Event.ENTER_FRAME, this.musicAnimation, this ); 
                        GLOBAL_CHANNEL = this['MUSIC' + this.CURRENT_LEVEL].play(0,1);
                        GLOBAL_MUSIC = this['MUSIC' + this.CURRENT_LEVEL];
                        this.playMucis(this.CURRENT_CONFIG.duration) 
                    }
                },1000)

                if(this.CURRENT_CONFIG.preList){
                    setTimeout(() => {
                        this.addEventListener( egret.Event.ENTER_FRAME, this.musicAnimation, this ); 
                        GLOBAL_CHANNEL = this['MUSIC' + this.CURRENT_LEVEL + '2'].play(0,1);
                        GLOBAL_MUSIC = this['MUSIC' + this.CURRENT_LEVEL + '2']
                        this.playMucis(this.CURRENT_CONFIG.duration) 
                    },6000 + this.CURRENT_CONFIG.duration1)
                }
            }else {
                setTimeout(() => {
                    this.addEventListener( egret.Event.ENTER_FRAME, this.musicAnimation, this ); 
                    GLOBAL_CHANNEL = this['MUSIC' + this.CURRENT_LEVEL + '1'].play(0,1);
                    GLOBAL_MUSIC = this['MUSIC' + this.CURRENT_LEVEL + '1']
                    this.playMucis(this.CURRENT_CONFIG.duration1) 
                },1000)

                setTimeout(() => {
                    egret.Tween.pauseTweens(this.TIMELINE)
                    egret.Tween.pauseTweens(this.RIGHTSHADOW)
                    this.TIMELINE.width = 340;
                    this.RIGHTSHADOW.x = 480;
                    this.addEventListener( egret.Event.ENTER_FRAME, this.musicAnimation, this ); 
                    GLOBAL_CHANNEL = this['MUSIC' + this.CURRENT_LEVEL + '2'].play(0,1);
                    GLOBAL_MUSIC = this['MUSIC' + this.CURRENT_LEVEL + '2']
                    this.playMucis(this.CURRENT_CONFIG.duration2) 
                },6000 + this.CURRENT_CONFIG.duration1)
            }

            this.startGame();
        }, this);
    }

    private startGame() {
        this.TITLE.text = this.CURRENT_CONFIG.title
        this.initLevel();
        this.addChild(this.GAME_PANEL);
    }

    private playMucis(duration) {
        this.addEventListener( egret.Event.ENTER_FRAME, this.musicAnimation, this ); 
        setTimeout(() => {
            this.removeEventListener( egret.Event.ENTER_FRAME, this.musicAnimation, this ); 
        },duration)
    }

    private musicAnimation() {
        this.frameCount ++;
        if(this.frameCount % 2 === 0){
            this.MUSIC_BTN.texture = RES.getRes(`frame${this.FRAME}_png`);
            this.FRAME ++;
            if(this.FRAME === 13) this.FRAME = 0;
        }
    }

    private initLevel() {
        if(this.CURRENT_CONFIG.initLevel) this.CURRENT_CONFIG.initLevel(this)
        let targetList = this.CURRENT_CONFIG.targetList;
        let qsList = this.CURRENT_CONFIG.qsList;
        let preList = this.CURRENT_CONFIG.preList;


        if(this.CURRENT_LEVEL === 25){
            let lastQs = new eui.Component();
            lastQs.skinName = 'lastQs';
            lastQs.y = 267;
            this.GAME_PANEL.addChild(lastQs);

            let top = lastQs.getChildByName('top');
            let bottom: any = lastQs.getChildByName('bottom');


            lastQs.removeChild(top);
            bottom.y = 0;

            this.COUNTDOWN.text = '5s';

            setTimeout(() => {
                this.intiCountDown5();
            },1000 + this.CURRENT_CONFIG.duration1)

            setTimeout(() => {
                this.changeNum('as5',bottom, 'type1');
            },1000 +  this.CURRENT_CONFIG.duration1)

            setTimeout(() => {
                this.changeNum('as9',bottom, 'type1');
            },1000 +  1000 + this.CURRENT_CONFIG.duration1)

            setTimeout(() => {
                this.changeNum('as1',bottom, 'type1');
            },1000 +  2000 + this.CURRENT_CONFIG.duration1)

            setTimeout(() => {
                this.changeNum('as5',bottom, 'type1');
            },1000 +  3000 + this.CURRENT_CONFIG.duration1)

            setTimeout(() => {
                this.COUNTDOWN.text = '15s';
                if(this.COUNTDOWN_THREAD) clearInterval(this.COUNTDOWN_THREAD);
                this.TITLE.text = this.CURRENT_CONFIG.title2;
                lastQs.addChild(top);
                bottom.y = 170.33;
                setTimeout(() => {
                    this.intiCountDown();
                    for(let i = 1; i<= 9; i++) {
                        let item = `as${i}t`;
                        bottom.getChildByName(item).addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
                            this.changeNum(`as${i}`, bottom, 'type2', top);
                        }, this);
                    }
                },this.CURRENT_CONFIG.duration2)
            }, 6000 + this.CURRENT_CONFIG.duration1)

            return 
        }


        if(preList) {
            this.COUNTDOWN.text = '5s';
            setTimeout(() => {
                this.intiCountDown5();
            },1000 + this.CURRENT_CONFIG.duration1)
            preList.forEach((item) => {
                let image = this.createBitmapByName(item.imageUrl)
                image.x = item.x;
                image.y = item.y;
                image.width = item.width;
                image.height = item.height;
                this.GAME_PANEL.addChild(image);
            })

            setTimeout(() => {
                egret.Tween.pauseTweens(this.TIMELINE)
                egret.Tween.pauseTweens(this.RIGHTSHADOW)
                this.TIMELINE.width = 340;
                this.RIGHTSHADOW.x = 480;
                if(this.COUNTDOWN_THREAD) clearInterval(this.COUNTDOWN_THREAD);
                this.COUNTDOWN.text = '15s';
                this.TITLE.text = this.CURRENT_CONFIG.title2
                this.GAME_PANEL.removeChildren();
                if(qsList){
                    qsList.forEach((item) => {
                        let image = this.createBitmapByName(item.imageUrl)
                        image.x = item.x;
                        image.y = item.y;
                        image.width = item.width;
                        image.height = item.height;
                        this.GAME_PANEL.addChild(image);
                    })
                }
                let needRegisterEvent = [];
                if(targetList) {
                    targetList.forEach((item) => {
                        let image = this.createBitmapByName(item.imageUrl);
                        image.name = item.name;
                        image.x = item.x;
                        image.y = item.y;
                        image.width = item.width;
                        image.height = item.height;
                        this.GAME_PANEL.addChild(image);
                        needRegisterEvent.push(image)
                    })
                }
                setTimeout(() => {
                    this.intiCountDown();
                    needRegisterEvent.forEach((item) => {
                        this.CURRENT_CONFIG.registerEvent(item, this);
                    })
                }, this.CURRENT_CONFIG.duration);
            }, 6000 + this.CURRENT_CONFIG.duration1)
        }else {
            if(qsList){
                qsList.forEach((item) => {
                    let image = this.createBitmapByName(item.imageUrl)
                    image.x = item.x;
                    image.y = item.y;
                    image.width = item.width;
                    image.height = item.height;
                    this.GAME_PANEL.addChild(image);
                })
            }
            let needRegisterEvent = [];
            if(targetList) {
                targetList.forEach((item) => {
                    let image = this.createBitmapByName(item.imageUrl);
                    image.name = item.name;
                    image.x = item.x;
                    image.y = item.y;
                    image.width = item.width;
                    image.height = item.height;
                    this.GAME_PANEL.addChild(image);
                    needRegisterEvent.push(image)
                })
            }
            setTimeout(() => {
                this.intiCountDown();
                needRegisterEvent.forEach((item) => {
                    this.CURRENT_CONFIG.registerEvent(item, this);
                })
            }, 1000 + this.CURRENT_CONFIG.duration);

        }
    }

    private changeNum(num, target, type, top?) {
        let content = target.getChildByName(num);
        let contentWrapper = target.getChildByName(num + 'w');
        contentWrapper.texture = RES.getRes(`rect2_png`)
        content.textColor = 0xFFFFFF;
        if(type === 'type1'){
            setTimeout(() => {
                content.textColor = 0x000000;
                contentWrapper.texture = RES.getRes(`rect_png`)
            }, 1000)
        }else if(type === 'type2'){
            this.LAST_COUNTER.push(num);
            let current = this.LAST_COUNTER.length;
            if(current === 1){
                if(this.LAST_COUNTER[0] === 'as5') {
                    this.SUCCESS_MUSIC.play(0,1)
                }else {
                    this.FAIL_MUSIC.play(0,1)
                }
            }else if(current === 2){
                if(this.LAST_COUNTER[1] === 'as9') {
                    this.SUCCESS_MUSIC.play(0,1)
                }else {
                    this.FAIL_MUSIC.play(0,1)
                }
            }else if(current === 3){
                if(this.LAST_COUNTER[2] === 'as1') {
                    this.SUCCESS_MUSIC.play(0,1)
                }else {
                    this.FAIL_MUSIC.play(0,1)
                }
            }
            top.getChildByName(`num${current}`).text = num.replace('as','');
            top.getChildByName(`rect${current}`).texture = RES.getRes(`rect_png`)
            if(current === 4) {
                if(this.LAST_COUNTER[0] === 'as5' && this.LAST_COUNTER[1] === 'as9' && 
                    this.LAST_COUNTER[2] === 'as1' && this.LAST_COUNTER[3] === 'as5'){
                        this.showSuccessPage(this.CURRENT_CONFIG.type)
                }else {
                    this.showFailPage();
                }
            }
            setTimeout(() => {
                content.textColor = 0x000000;
                contentWrapper.texture = RES.getRes(`rect_png`);
            }, 100)
        }
    }

    private intiCountDown() {
        GLOBAL_CHANNEL = ''
        this.TIMELINE.width = 340;
        this.RIGHTSHADOW.x = 480;
        egret.Tween.get(this.TIMELINE, {
            loop: false,//设置循环播放
            onChangeObj: this//更新函数作用域
        })
        .to({width: 0}, 15000)//设置2000毫秒内 rotation 属性变为360
        .call(() => {
        }, this);

        egret.Tween.get(this.RIGHTSHADOW, {
            loop: false,//设置循环播放
            onChangeObj: this//更新函数作用域
        })
        .to({x: 140}, 15000)//设置2000毫秒内 rotation 属性变为360
        .call(() => {
        }, this);

        this.COUNTDOWN.text = '15s';
        if(this.COUNTDOWN_THREAD) clearInterval(this.COUNTDOWN_THREAD);

        this.COUNTDOWN_THREAD = setInterval(() => {
            if(parseInt(this.COUNTDOWN.text) === 0) {
                 clearInterval(this.COUNTDOWN_THREAD);
                 this.showFailPage('delay')
            }else {
                this.COUNTDOWN.text = parseInt(this.COUNTDOWN.text) - 1 + 's';
            }
        }, 1000)
    }

    private intiCountDown5() {
        this.TIMELINE.width = 340;
        this.RIGHTSHADOW.x = 480;
        egret.Tween.get(this.TIMELINE, {
            loop: false,//设置循环播放
            onChangeObj: this//更新函数作用域
        })
        .to({width: 0}, 5000)//设置2000毫秒内 rotation 属性变为360
        .call(() => {
        }, this);
        egret.Tween.get(this.RIGHTSHADOW, {
            loop: false,//设置循环播放
            onChangeObj: this//更新函数作用域
        })
        .to({x: 140}, 5000)//设置2000毫秒内 rotation 属性变为360
        .call(() => {
        }, this);
        
        this.COUNTDOWN.text = '5s';
        if(this.COUNTDOWN_THREAD) clearInterval(this.COUNTDOWN_THREAD);

        this.COUNTDOWN_THREAD = setInterval(() => {
            if(parseInt(this.COUNTDOWN.text) === 0) {
                 clearInterval(this.COUNTDOWN_THREAD);
                 this.showFailPage('delay')
            }else {
                this.COUNTDOWN.text = parseInt(this.COUNTDOWN.text) - 1 + 's';
            }
        }, 1000)
    }

    private showSuccessPage(type) {
        this.SCORE_REGISTER[type] += 20;
        $.ajax({
            url: GLOBAL_PATH + '/question/report/record',
            method:'POST',
            headers: {
                'Content-Type': "application/json;charset=UTF-8"
            },
            data: JSON.stringify({
                userId: USER_ID,
                reportId: this.QS_ID,
                questionIndex: this.CURRENT_LEVEL,
                result: 2,
                math:this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.math : '',
                observation: this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.observation : '',
                space: this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.space : '',
                memory: this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.memory : '',
                illation: this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.illation : '',
            }),
            success:(res) => {
                
            }
        })
        if(this.COUNTDOWN_THREAD) clearInterval(this.COUNTDOWN_THREAD);
        egret.Tween.pauseTweens(this.TIMELINE)
        egret.Tween.pauseTweens(this.RIGHTSHADOW)
        setTimeout(() => {
            // this.SUCCESS_MUSIC.play(0,1)
            setTimeout(() => {
                if(this.CURRENT_LEVEL === 25){
                    QSID = this.QS_ID;
                    CANREAD = false;
                    return SceneMange.getInstance().changeScene('resultGame', this.SCORE_REGISTER);
                }
                this.GAME_PANEL.removeChildren();
                this.CURRENT_LEVEL ++;
                this.showLevelLabel();
            }, 1000) 
        }, 500)
    }

    private showFailPage(delay?) {
        this.FAIL_MUSIC.play(0,1)
         $.ajax({
            url: GLOBAL_PATH + '/question/report/record',
            method:'POST',
            headers: {
                'Content-Type': "application/json;charset=UTF-8"
            },
            data: JSON.stringify({
                userId: USER_ID,
                reportId: this.QS_ID,
                questionIndex: this.CURRENT_LEVEL,
                result: delay ? 4 : 3,
                math:this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.math : '',
                observation: this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.observation : '',
                space: this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.space : '',
                memory: this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.memory : '',
                illation: this.CURRENT_LEVEL === 25 ? this.SCORE_REGISTER.illation : '',
            }),
            success:(res) => {
                
            }
        })
        if(this.COUNTDOWN_THREAD) clearInterval(this.COUNTDOWN_THREAD);
        egret.Tween.pauseTweens(this.TIMELINE)
        egret.Tween.pauseTweens(this.RIGHTSHADOW)
        setTimeout(() => {
            setTimeout(() => {
                if(this.CURRENT_LEVEL === 25){
                    QSID = this.QS_ID;
                    CANREAD = false;
                    return SceneMange.getInstance().changeScene('resultGame', this.SCORE_REGISTER);
                }
                this.GAME_PANEL.removeChildren();
                this.CURRENT_LEVEL ++;
                this.showLevelLabel();
            }, 1000) 
        }, 500)
    }

    public getRightIcon(x,y) {
        let image = this.createBitmapByName('right_png')
        image.x = x;
        image.y = y;
        image.width = translatePx(18);
        image.height = translatePx(18);
        this.GAME_PANEL.addChild(image);
    }

    private flyAnimation(origin, target, callback) {
        let image = this.createBitmapByName(origin.imageUrl)
        image.x = origin.x;
        image.y = origin.y;
        image.width = origin.width;
        image.height = origin.height;
        this.GAME_PANEL.addChild(image);

        egret.Tween.get(image, {
            loop: false,//设置循环播放
            onChangeObj: this//更新函数作用域
        })
        .to({x:target.x, y:target.y, width: target.width, height: target.height}, 500)//设置2000毫秒内 rotation 属性变为360
        .call(() => {
            callback()
        }, this);
    }

    private flyAnimation2(origin, target, callback, special) {
        let image = this.createBitmapByName(origin.imageUrl)
        image.x = origin.x;
        image.y = origin.y;
        image.width = origin.width;
        image.height = origin.height;
        this.GAME_PANEL.addChild(image);

        egret.Tween.get(image, {
            loop: false,//设置循环播放
            onChangeObj: this//更新函数作用域
        })
        .to({x:target.x, y:target.y, width: target.width, height: target.height, alpha: 0}, 500)//设置2000毫秒内 rotation 属性变为360
        .call(() => {
        }, this);

        let image2 = this.createBitmapByName(special.imageUrl)
        image2.x = special.x;
        image2.y = special.y;
        image2.width = special.width;
        image2.height = special.height;
        image2.alpha = 0;
        this.GAME_PANEL.addChild(image2);

        egret.Tween.get(image2, {
            loop: false,//设置循环播放
            onChangeObj: this//更新函数作用域
        })
        .wait(500)
        .to({alpha: 1}, 500)//设置2000毫秒内 rotation 属性变为360
        .wait(500)
        .call(() => {
            callback()
        }, this);
    }
}